/**
 *
 */
package jp.seraph.jsade.perceptor;

import org.apache.commons.math.geometry.Vector3D;

import jp.seraph.jsade.math.Point3D;
import jp.seraph.jsade.sexpression.Node;

/**
 *
 *
 */
public class ForceResistanceBulder implements PerceptorBuilder {

    /**
     *
     * @see jp.seraph.jsade.perceptor.PerceptorBuilder#build(jp.seraph.jsade.sexpression.Node)
     */
    public Perceptor build(Node aNode) {
        String tName = aNode.getValue("n");
        String[] tCentorValues = aNode.getValues("c");
        String[] tForceValues = aNode.getValues("f");

        if (tName == null || tCentorValues.length != 3 || tForceValues.length != 3)
            throw new IllegalArgumentException("ノードの構造が想定のものと違います。");

        Double tPointX = Double.parseDouble(tCentorValues[0]);
        Double tPointY = Double.parseDouble(tCentorValues[1]);
        Double tPointZ = Double.parseDouble(tCentorValues[2]);
        Double tForceX = Double.parseDouble(tForceValues[0]);
        Double tForceY = Double.parseDouble(tForceValues[1]);
        Double tForceZ = Double.parseDouble(tForceValues[2]);

        return new ForceResistancePerceptor(tName, new Point3D(tPointX, tPointY, tPointZ), new Vector3D(tForceX, tForceY, tForceZ));
    }
}
